package kg.aibek.projecteuler.p10;

import java.util.ArrayList;
import java.util.Collections;

public class Problem38 {
	public void solve() {
		for (int i = 9999; i > 9000; i--) {
			if (isPandigital(i, i * 2)) {
				System.out.println(i + "" + (i * 2));
			}
		}
	}

	private boolean isPandigital(int a, int b) {
		ArrayList<Integer> list = new ArrayList<Integer>();
		while (a > 0) {
			list.add(a % 10);
			a = a / 10;
		}

		while (b > 0) {
			list.add(b % 10);
			b = b / 10;
		}

		if (list.size() != 9)
			return false;

		Collections.sort(list);
		for (int i = 0; i < 9; i++) {
			if (i + 1 != list.get(i))
				return false;
		}
		return true;
	}

	public static void main(String[] args) {
		Problem38 p = new Problem38();
		p.solve();
	}
}
